// @/api/userApi.ts
import request from "@/utils/request";

// 用户实体类型
export interface UserMaster {
  UserId: string;
  UserName: string;
  Password?: string;
  PwdStatus?: string;
  UserRole: string;
  UserPhoneNo?: string;
  UserEmail?: string;
  DeptCode: string;
  ReportingTo?: string;
  Status: string;
  InactiveDate?: string;
  LastLoginDate?: string;
  CreatedBy?: string;
  CreatedAt?: string;
  ModifiedBy?: string;
  ModifiedAt?: string;
}

// 添加用户
export function addUser(data: UserMaster) {
  return request<string>({
    url: "/UserMaster/Add",
    method: "POST",
    data
  });
}

// 更新用户
export function updateUser(data: UserMaster) {
  return request({
    url: "/UserMaster/Update",
    method: "PUT",
    data
  });
}

// 删除用户
export function deleteUser(userId: string) {
  return request({
    url: `/UserMaster/Delete/${userId}`,
    method: "DELETE"
  });
}

// 获取用户详情
export function getUserById(userId: string) {
  return request<UserMaster>({
    url: `/UserMaster/GetById/${userId}`,
    method: "GET"
  });
}

// 分页查询
export function getUserPag(search: any, pageNum: number, pageSize: number) {
  return request({
    url: `/UserMaster/GetUserPage?pageNum=${pageNum}&pageSize=${pageSize}`,
    method: "POST",
    data: search
  });
}

// 获取部门下的用户
export function getUsersByDept(deptCode: string) {
  return request<UserMaster[]>({
    url: `/UserMaster/GetByDept/${deptCode}`,
    method: "GET"
  });
}

// 更新用户状态
export function updateUserStatus(userId: string, status: string, inactiveDate?: string) {
  return request({
    url: `/UserMaster/UpdateStatus/${userId}`,
    method: "POST",
    data: { status, inactiveDate }
  });
}

// 重置用户密码
export function resetUserPassword(userId: string) {
  return request({
    url: `/UserMaster/ResetPassword/${userId}`,
    method: "POST"
  });
}